﻿<%@ Page Language="C#" Title="宝贝归类" AutoEventWireup="true" CodeBehind="ItemSeller_cateitem.aspx.cs" Inherits="map.member.dialogs.ItemSeller_cateitem" %>

<%@ Register Assembly="RuleCode.Common" Namespace="RuleCode.Controls" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style type="text/css">
        .mainitemcateDiv
        {                                                                  
            width:820px;
        }
        .itemcateToolDiv
        {
            height:25px;
            font-size:small;
            width:100%;
        }
        .input-button,.input-submit{background-color:#005eac;border-color:#b8d4e8 #124680 #124680 #b8d4e8;border-style:solid;border-width:1px;color:#fff;cursor:pointer;font-size:12px;padding:2px 15px;text-align:center}
        .itemcateContentDiv
        {
            width:100%;
            border-top:solid 1px #B2D1FF;
            margin-top:20px;
        }
        .itemcateContentHeaderDiv
        {
            border-bottom:solid 1px lightGray;
            background-color:#F2F8FF;
            height:28px;
            font-size:small;
            vertical-align:middle;
        }
        .list_td0
        {
            width:5%;
            text-align:center;
        }
        .list_td1
        {
            width:12%;
        }
        .list_td2
        {
            width:28%;
        }
        .list_td3
        {
            width:15%;
            text-align:center;
        }
        .list_td4
        {
            width:25%;
            text-align:left;
            
        }
        .list_td5
        {
            width:15%;
            vertical-align:top;
        }
        .itemcateContentBodyDiv
        {
            width:100%;
        }
        .NoDataDiv
        {
            font-size:small;
            text-align:left;
            height:25px;
            line-height:25px;
            vertical-align:middle;
        }
        .itemcateFooterDiv
        {
            width:100%;
            text-align:left;
            font-size:small;
        }
        .optionDisabled
        {
        }
        .childOption
        {
            background:url(../img/forum.gray2-16x16.gif);
            padding-left:10px;
        }
        .list_td4 ul li
        {
            display:block;
            list-style-type:none;
            font-size:small;
            text-align:left;
            position:relative;
            left:-30px;
        }
        .list_td4 ul li a
        {
            background:url(../../img/close.png) no-repeat  scroll 0px -9px ;
            overflow:hidden;
            height:9px;
            padding-left:9px;
            text-decoration:none;
            margin-left:10px;
            margin-top:9px;
        }
        .list_td4 ul
        {
            text-align:left;
        }
        .itemcateselectPopupDiv
        {
            overflow :auto;
            background-color:white;
            border:solid 1px Gray;
            text-align:left;
         }
         .itemcateselectPopupDiv ul li
         {
             font-size:small;
             list-style-type:none;
             left:-30px;
             position:relative;
         }
         .showItemcateSelButton
         {
             line-height:23px;
             height:23px;
             background:url(../../img/add-button.png) no-repeat;
             font-size :12px;
             float:left;
             text-indent:35px;
             width:127px;
             text-decoration:none;
         }
         .hiddenObject
         {
             visibility:hidden;
         }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
             <div class="mainitemcateDiv" id="mainitemcateDiv">
             <div class="itemcateToolDiv">
                <table width="100%">
                    <tr>
                        <td style =" text-align:left; width:50%">
                            请选择分类：
                            <asp:DropDownList ID="SelItemCateDropDownList0" AutoPostBack ="true" Height="20px" Width="100px" runat="server" OnSelectedIndexChanged ="SelItemCateDropDownList0_SelectedIndexChanged">
                            </asp:DropDownList> 
                            <asp:DropDownList ID="SelItemCateDropDownList1" AutoPostBack ="true" Height="20px" Width="100px" runat="server" OnSelectedIndexChanged ="SelItemCateDropDownList1_SelectedIndexChanged">
                            </asp:DropDownList>   
                        </td>
                        <td style =" text-align:right; width:50%">
                            宝贝搜索：
                            <asp:TextBox ID="searchKeysTextBox"  Height="15px" MaxLength="30" runat="server"></asp:TextBox>
                            <asp:Button ID="searchItemButton" runat="server" Text="搜索"  
                                CssClass="input-button" onclick="searchItemButton_Click"/>
                        </td>
                    </tr>
                </table>
             </div>
             
             <div class="itemcateContentDiv">
                  <div class="itemcateContentHeaderDiv">
                    <table style ="margin-top:5px; width:100%;">
                        <tr>
                            <td class="list_td0"></td>
                            <td class="list_td1">宝贝图片</td> 
                            <td class="list_td2">宝贝描述</td>
                            <td class="list_td3">编辑宝贝</td>
                            <td class="list_td4">所属分类</td>                                
                            <td class="list_td5">添加所属分类</td>
                        </tr>
                    </table>
                  </div>
                  
                  <div class="itemcateContentBodyDiv">
                     <div class="NoDataDiv" id="NoDataDiv" runat="server">
                        对不起，该分类下暂无宝贝！
                     </div>
                      <asp:DataList ID="MainDataList" DataKeyField="RECID" Width="100%" runat="server">
                         <ItemTemplate>
                            <table width="100%" onmouseover ="this.bgColor='lightblue';" onmouseout ="this.bgColor='white';">
                                <tr>
                                    <td class="list_td0" style=" background-color:lightGray">
                                        <asp:CheckBox ID="ItemSelectCheckBox" runat="server" />
                                    </td>
                                    <td class="list_td1">
                                        &nbsp;<a target ="_blank" style=" border:none" title="点击查看商品详细信息" href ='<%#GetItemUrl(Eval("RECID").ToString()) %>'><img style=" border:none; width:50px;height:50px;"  alt="暂无图片" src ='<%#Eval("taobaopic_path") %>'/></a>
                                    </td>
                                    <td class="list_td2">
                                        <a target ="_blank" href ='<%#GetItemUrl(Eval("RECID").ToString()) %>' title='<%#Eval("taobaotitle") %>' style =" text-decoration:none; font-size:small; line-height:20px; width:100px; vertical-align:top;"><%#Eval("taobaotitle").ToString()%></a>
                                    </td>
                                    <td class="list_td3">
                                        <a target ="_blank" title="编辑宝贝信息" href='<%# "../ItemInfo.aspx?type=edit&id="+Eval("taobaoiid").ToString() %>'><img alt="" style =" border:none" src="../../img/edititem.gif"/></a>&nbsp;
                                    </td>
                                    <td class="list_td4">
                                        <%#GetCateListUlHtml(Eval ("taobaoseller_cids").ToString (),Eval ("RECID").ToString())%>
                                        <input  type="hidden" value='<%#Eval("RECID").ToString() %>'/>
                                    </td>
                                    <td class="list_td5">
                                        <a  href ="#" class="showItemcateSelButton" onclick ="showItemCateSelDiv(this);">添加所属分类</a>                                        
                                    </td>
                                </tr>
                            </table>
                         </ItemTemplate>
                      </asp:DataList>
                      
                      <div class="itemcateContentHeaderDiv" style =" border-top:solid 1px #B2D1FF; margin-top:2px; padding-top:5px; border-top:solid 1px lightBlue; width:100%">
                            <asp:CheckBox ID="SelectAllCheckBox" runat="server"  AutoPostBack="True" Text="全选" 
                                oncheckedchanged="SelectAllCheckBox_CheckedChanged"/>
                             <asp:CheckBox ID="SelectOthersCheckBox" runat="server"   AutoPostBack="True"  Text="反选" 
                                oncheckedchanged="SelectOthersCheckBox_CheckedChanged"/>
                             <asp:DropDownList ID="OprNameDropDownList"  AutoPostBack="true" Height="20px"  
                                Width="100px" runat="server" 
                                onselectedindexchanged="OprNameDropDownList_SelectedIndexChanged">
                                <asp:ListItem Value ="" Text ="选择分类操作"  Selected="True"></asp:ListItem>
                                <asp:ListItem Value ="Add" Text="批量添加"></asp:ListItem>
                                <asp:ListItem Value ="Move" Text="批量移动" ></asp:ListItem>
                             </asp:DropDownList>
                             宝贝到
                             
                             <asp:DropDownList ID="OprItemCateDropDownList0"  AutoPostBack="true" Height="20px"  
                                Width="100px" runat="server" 
                                onselectedindexchanged="OprItemCateDropDownList0_SelectedIndexChanged" >
                             </asp:DropDownList>
                             <asp:DropDownList ID="OprItemCateDropDownList1"  AutoPostBack="true" Height="20px"  
                                Width="100px" runat="server" >
                             </asp:DropDownList>
                             <input  type="button" id="OprOkButton" value="确定" onclick ="cateOprOkButtonClick();"/>
                             <%--<input  type="button" id="CateOprOkButton" runat ="server" value="确定"  onserverclick ="CateOprOkButton_Click"/>--%>
                             <asp:Button ID="CateOprOkButton" CssClass ="hiddenObject" Height="20px" runat="server" Text="确定" 
                                onclick="CateOprOkButton_Click" />
                      </div>
                      
                      <div class="itemcateFooterDiv" style="margin-top:2px; background-color:#ECECEC">                        
                        <cc1:WebPager ID="MainWebPager" runat="server"  
                                        ControlToPaginate="MainDataList"  PageSize="10" 
                                        onpageindexchanged="MainWebPager_PageIndexChanged" /> 
                      </div>
                      
                  </div>
             </div>
            
            <div id="itemcateselectPopupDiv" class ="itemcateselectPopupDiv" style =" display:none; position:absolute;">
                <ul id="itemcateselectPopupUl">
                </ul>
            </div>
        </div>  
        </ContentTemplate>
    </asp:UpdatePanel>
       
    </form>
    
    <script type ="text/javascript">
        var PageUtil = window.PageUtil || {};
        PageUtil = {
            IndexOf: function(array, element) {
                for (var i = 0; i < array.length; i++) {
                    if (array[i] == element)
                        return i;
                }
                return -1;
            }
        };

        function cateOprOkButtonClick() {
            var cateOprOKButton = document.getElementById("CateOprOkButton");
            var OprNameSelect = document.getElementById("OprNameDropDownList");
            var selectedOprName = OprNameSelect[OprNameSelect.selectedIndex].value;
            if (selectedOprName == "") {
                alert("您还未选择操作！");
                return;
            }
            else {
                if (selectedOprName == "Move") {
                    var result = confirm("您的宝贝可能有多个分类，选择移动分类会将以前的分类清除。确定要移动宝贝分类？");
                    if (result != true) {
                        return ;
                    }
                }
            }
            cateOprOKButton.click();
        }
        //如果是被放在一个iframe里面。对其自适应高度
        function initFrameHeight() {
            if (window.parent != null) {
                document.getElementById("mainitemcateDiv").style.width = screen.availWidth - 220 + "px";
                var frameObj = window.parent.document.getElementById("CateOprFrame");
                if (frameObj != null) {
                    frameObj.style.height = document.getElementById("mainitemcateDiv").offsetHeight + 200 + "px";
                    frameObj.style.width = screen.availWidth - 200 + "px";
                } 
            }
        }
        window.onload = function() {
            initFrameHeight();
        }
        //移除分类
        function removeItemCate(thisObj) {
            var parentObj = thisObj.parentNode;
            var ulELe = parentObj.parentNode;
            var spanEle = parentObj.getElementsByTagName("span")[0];
            var cateId = parentObj.id;
            var itemRecId =spanEle .id;
            var result = AjaxFunction.removeItemSellerCate(itemRecId, cateId);
            if (result.value != null && result.value == true) {
                ulELe.removeChild(parentObj);
            }
        }
        //初始化分类框
        function inititemcatePopDiv(targetUl) {
            var itemcateselectpopupUl = document.getElementById("itemcateselectPopupUl");
            itemcateselectpopupUl.innerHTML = "";
            var oldCateEleList = targetUl.getElementsByTagName("li");
            var oldCateIdList = new Array();
            for (var i = 0; i < oldCateEleList.length; i++) {
                oldCateIdList.push(oldCateEleList[i].id); 
            }
            var result = AjaxFunction.getAllLeaveCate();
            if (result.value != null && result.value != "") {
                var cateList = eval(result.value);
                for (var i = 0; i < cateList.length; i++) {
                    var newLiEle = document.createElement("li");
                    newLiEle.id = cateList[i].cid;
                    if (cateList[i].pname != "")
                        newLiEle.innerHTML = cateList[i].pname + ">>" + cateList[i].name;
                    else
                        newLiEle.innerHTML = cateList[i].name;

                    if (PageUtil.IndexOf(oldCateIdList, cateList[i].cid) >= 0) {
                        newLiEle.style.backgroundColor = "red";
                        newLiEle.onmouseover = function() { this.style.cursor = "not-allowed"; }
                        newLiEle.onmouseout = function() { this.style.cursor = "pointer"; }
                    }
                    else {
                        newLiEle.onmouseover = function() { this.style.backgroundColor = "lightGray"; this.style.cursor = "pointer"; }
                        newLiEle.onmouseout = function() { this.style.backgroundColor = "white"; }
                        newLiEle.onclick = function() {
                        var itemRECIDHiddenEle = targetUl.parentNode.getElementsByTagName("input")[0]; //alert(targetUl.parentNode.getElementsByTagName("input")[0].value);
                            var result = AjaxFunction.AddSellerItemCate(itemRECIDHiddenEle.value, this.id);
                            if (result.value != null && result.value == true) {
                                var newitemCateLiEle = document.createElement("li");
                                newitemCateLiEle.id = this.id;
                                newitemCateLiEle.innerHTML = "<span id=\"" + itemRECIDHiddenEle.value + "\">" + this.innerHTML + "</span><a href=\"#\" onclick=\"removeItemCate(this)\">&nbsp;</a>";
                                targetUl.appendChild(newitemCateLiEle);
                                return false;
                            }
                        };
                    }
                    itemcateselectpopupUl.appendChild(newLiEle);
                }
            }
            else {
                var newLiEle = document.createElement("li");
                newLiEle.innerHTML = "<span style=\"color:red\">您还未定义商品分类！</span>";
                itemcateselectpopupUl.appendChild(newLiEle);
            }
        }
        //显示 添加商品分类 按钮 下面的分类框
        function showItemCateSelDiv(thisObj) {
            
            var targetUl = thisObj.parentNode.parentNode.getElementsByTagName("ul")[0];
            inititemcatePopDiv(targetUl); 
            var itemcateselectdiv = document.getElementById("itemcateselectPopupDiv");
            itemcateselectdiv.style.display = "block";
            itemcateselectdiv.style.position = "absolute"; 
            itemcateselectdiv.style.top = parseInt ( getTop(thisObj))+thisObj.offsetHeight+"px";
            itemcateselectdiv.style.left = getLeft(thisObj)+'px'; //alert(getLeft(thisObj));        
            return false;
        }

        //公用方法
        function getTop(e) {
            var offset = e.offsetTop;
            if (e.offsetParent != null) {
                if (e.offsetParent.style.position == "absolute") {
                    if (Sys.firefox)
                        offset += parseInt(e.offsetParent.style.top);
                    return offset;
                }
                offset += getTop(e.offsetParent);
            }
            return offset;
        }
        function getLeft(e) {
            var offset = e.offsetLeft;
            if (e.offsetParent != null) {
                if (e.offsetParent.style.position == "absolute") {
                    if (Sys.firefox)
                        offset += parseInt(e.offsetParent.style.left);
                    return offset;
                }
                offset += getLeft(e.offsetParent);
            }
            return offset;
        }

        document.body.onclick = function(event) {
            var itemcateselectPopupDiv = document.getElementById("itemcateselectPopupDiv");
            var event = window.event || event;
            var eventTarget = event.target || event.srcElement;
            if (itemcateselectPopupDiv.style.display != "none" && eventTarget.className != "showItemcateSelButton")
                itemcateselectPopupDiv.style.display = "none";
        }
        //取消事件冒泡
        function clearEventBubble(evt) {
            evt = evt || window.event;

            if (evt.stopPropagation) {
                evt.stopPropagation();
            } else {
                evt.cancelBubble = true;
            }

            if (evt.preventDefault) {
                evt.preventDefault();
            } else {
                evt.returnValue = false;
            }

        }
    </script>
</body>
</html>
